package javaio12.outputstreamdemo;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Copy
{

	public static void main(String[] args) throws IOException
	{
		if(args.length != 2)
		{
			System.out.println("您输入的参数不正确,请重新输入！");
			System.out.println("例如：java Copy 源文件  目标文件");
			System.exit(1);
		}
		// File f = new
		// File("E:"+File.separator+"study2012"+File.separator+"test.txt");
		File fin = new File(args[0]);
		if(!fin.exists())
		{
			System.out.println("指定的源文件不存在，请确认！");
			System.exit(1);
		}
		File fout = new File(args[1]);
		OutputStream out = null;
		InputStream in = null;
		try
		{
			out = new FileOutputStream(fout, true);
			in = new FileInputStream(fin);
		}
		catch(FileNotFoundException e)
		{
			e.printStackTrace();
		}
		// 输入和输出是否就绪
		if(out != null && in != null)
		{
			int temp;
			while((temp = in.read()) != -1)
			{
				try
				{
					out.write(temp);
				}
				catch(IOException e)
				{
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}

		try
		{
			out.close();
			in.close();
		}
		catch(IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
